package com.hj.dapp.business.unit.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hj.dapp.business.unit.model.Unit;
import com.hj.dapp.business.unit.service.UnitService;
import com.hj.dapp.common.request.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

/**
 * @author 胡奥程
 * @version 1.0
 * @date 2024/1/22
 */
@RestController
@RequestMapping("/unit")
public class UnitController {

    @Autowired
    private UnitService unitService;

    @GetMapping("/get/{id}")
    public Unit get(@PathVariable("id") Long id) {
        return unitService.get(id);
    }
    @PostMapping("/page")
    public IPage<Unit> page(@RequestBody PageRequest<Unit> request) {
        return unitService.page(request);
    }

    @PostMapping("/edit")
    public void edit(@RequestBody Unit unit, Principal principal) {
        unitService.edit(unit,principal);
    }
    @PutMapping("/save")
    public void save(@RequestBody Unit unit, Principal principal) {
        unitService.save(unit, principal);
    }

    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        unitService.delete(id);
    }
    @GetMapping("/list")
    public List<Unit> list() {
       return unitService.list();
    }
}
